function na=calNa(s)
n=s^2;
for i=1:ceil(0.16*n)
    qi=calQi(i,s);
    p=max(ceil(log2(i)),1);
    if n-3-p-qi<0
        na=i-1;
        break;
    else
        na=i;
    end
end
end

function qi=calQi(i,s)
qi=0; n=s^2;
for j=1:i
    qi=qi+ceil(log2(n-j+1));
end
end